package com.pokeoffice.logs;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

/**
 * The Class TestLogger.
 */
public class TestLogger {

	/** The RES. */
	public static TestType RES = TestType.RESULT;
	
	/** The STT. */
	public static TestType STT = TestType.START;
	
	/** The STP. */
	public static TestType STP = TestType.STOP;
	
	/** The TXT. */
	public static TestType TXT = TestType.TEXT;
	
	/** The Constant APPEND. */
	private static final boolean APPEND = true;

	/**
	 * Based on the type of log provided, the method switches to the correct log
	 * file and writes to the end of the log.
	 *
	 * @param t the t
	 * @param s the s
	 * @param test the test
	 */
	public static void write(TestType t, String s, String test) {
		try {
			BufferedWriter out = new BufferedWriter(new FileWriter(new File("files/results/" + test + ".tst"), APPEND));

			if (t == TestType.START || t == TestType.STOP) {
				String dateFormat = "yyyy:MM:dd::HH:mm:ss";
				Calendar cal = Calendar.getInstance();
				SimpleDateFormat sdf = new SimpleDateFormat(dateFormat);
				String time = "[" + sdf.format(cal.getTime()) + "] ";
				out.newLine();
				out.write(time + s);
				out.newLine();
			} else {
				out.write(s);
			}
			
			out.flush();
			out.close();
		} catch (IOException e) {
			Log.write(Log.ERR, "Error Writing Result");
		}
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	public String toString() {
		return "This class Logs actions performed";
	}

	/**
	 * The Enum TestType.
	 *
	 * @author   kyle
	 */
	private enum TestType {
		
		/** The RESULT. */
		RESULT, 
		
		/** The START. */
		START, 
		
		/** The STOP. */
		STOP, 
		
		/** The TEXT. */
		TEXT;
	}
}
